package com.tcfvic.server;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.tcfvic.server.tools.MapperHelper;

public abstract class AbstractService extends RemoteServiceServlet {

	private static final long serialVersionUID = -8058276521927226484L;

	@SuppressWarnings("unchecked")
	public <T> List<T> serialize(Collection<T> list) {
		ArrayList<T> dtoList = new ArrayList<T>();
		for (T a : list) {
			T dto = null;
			if (a != null) {
				dto = (T) MapperHelper.getInstance().map(a, a.getClass());
			}
			dtoList.add(dto);
		}
		return dtoList;
	}

	@SuppressWarnings("unchecked")
	public <T> T serialize(T o) {
		return (T) MapperHelper.getInstance().map(o, o.getClass());
	}

}
